package tests.library.classloader;

import library.classloader.*;
import java.lang.reflect.*;

public class testlaoder {

	public testlaoder() {
      System.out.println("testlaoder(...) constructor called");
	}
	
	public void print_testloader() {
      System.out.println("testlaoder.print_testloader(...) called");
	}

	public class testclassinside {

     public class testclassinsidel1 {
         public testclassinsidel1() {
             System.out.println("testclassinsidel1(...) constructor called");
           }

         public void print() {
           System.out.println("testclassinsidel1.print(...) called");
         }
    	 
     }
      public testclassinside() {
          System.out.println("testclassinside(...) constructor called");
        }

      public void print() {
        System.out.println("testclassinside.print(...) called");
      }
      
	}
	public static void main(String[] args) throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
		// TODO Auto-generated method stub
		
		ClassLoad cload = new ClassLoad();
		ClassLoadSingleton cloassingle;

		testlaoder tc = null;
		try {
		tc = (testlaoder)cload.getClass("tests.library.classloader.testlaoder");
		} catch (ClassNotFoundException ex) {
          ex.printStackTrace();
		} catch (InstantiationException ex) {
          ex.printStackTrace();
		}catch (IllegalAccessException ex) {
          ex.printStackTrace();
		}
		
		tc.print_testloader();
		
		cloassingle = new ClassLoadSingleton();

System.out.println("***************************************************************");
System.out.println("ClassLoadSingleton test");

		try {
         tc = (testlaoder)cloassingle.getClass("tests.library.classloader.testlaoder");
         tc.print_testloader();
         tc = (testlaoder)cloassingle.getClass("tests.library.classloader.testlaoder");
         tc.print_testloader();
         
//         System.out.println(testclassinside.class.getName());

         Object parent = Class.forName("tests.library.classloader.testlaoder").newInstance();
         for (Class<?> cls : parent.getClass().getDeclaredClasses()) {
        	 System.out.println("class name: " + cls.getName());
             if (!Modifier.isStatic(cls.getModifiers())) {
                 // This is an inner class. Pass the parent class in.
                 cls.getDeclaredConstructor(new Class[] { parent.getClass() }).newInstance(new Object[] { parent });
             } else {
                 // This is a nested class. You can also use it here as follows:
                 cls.getDeclaredConstructor(new Class[] {}).newInstance(new Object[] {});
             }
         }

         
         System.out.println("\n\n\n\n");
         testlaoder.testclassinside tci = (testlaoder.testclassinside)cloassingle.getClass("tests.library.classloader.testlaoder$testclassinside");
         tci.print();
         System.out.println("\n\n\n\n");

         testlaoder.testclassinside.testclassinsidel1 tci1 = (testlaoder.testclassinside.testclassinsidel1)cloassingle.getClass("tests.library.classloader.testlaoder$testclassinside$testclassinsidel1");
         tci1.print();
         tci1 = (testlaoder.testclassinside.testclassinsidel1)cloassingle.getClass("tests.library.classloader.testlaoder$testclassinside$testclassinsidel1");
         tci1.print();

		} catch (ClassNotFoundException ex) {
          ex.printStackTrace();
		} catch (InstantiationException ex) {
          ex.printStackTrace();
		}catch (IllegalAccessException ex) {
          ex.printStackTrace();
		}

System.out.println("***************************************************************");
System.out.println("%%%% end test function %%%");
	}
}
